import {getStorage, setStorage} from 'hcg-storage';

let bargainList = getStorage('bargainList') || [];
export default {
	state: bargainList,
	actions: {
		setBargainList({commit}, bargainData) {
			let list = [...bargainData.result];
			list.forEach(item => {
				let goods = bargainData.goodsMap[item.goodsId];
				item.goods = Object.assign({}, goods);
			});
			commit('setBargainList', list);
		},
	},
	mutations: {
		setBargainList(state, bargainList) {
			state.splice(0);
			for (let item of bargainList) {
				state.push(item);
			}
			setStorage('bargainList', state);
		},
	}
}
